﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>
    <!-- jsp文件头和头部 -->
    <%@ include file="../../system/index/top.jsp" %>
    <!-- 日期框 -->
    <link rel="stylesheet" href="static/ace/css/datepicker.css"/>
</head>
<body class="no-skin">

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- 检索  -->
                        <form action="plantbase/goDeliveryList" method="post" name="plantbaseForm"
                              id="plantbaseForm">
							<input type="hidden" id="baseId" value="${pd.id }"/>
                            <!-- 检索  -->
                            <table id="simple-table"
                                   class="table table-striped table-bordered table-hover"
                                   style="margin-top: 5px;">
                                <thead>
                                <tr>
                                    <th class="center">ID</th>
                                    <th class="center">基地名称</th>
                                    <th class="center">发货地址</th>
                                    <th class="center">责任人</th>
                                    <th class="center">责任人手机号</th>
                                    <th class="center"><i
                                        class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i>修改日期
                                    </th>
                                    <th class="center">状态</th>
                                    <th class="center">操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <!-- 开始循环 -->
                                <c:choose>
                                    <c:when test="${not empty deliveryList}">
                                        <c:if test="${QX.cha == 1 }">
                                            <c:forEach items="${deliveryList}" var="plantBase"
                                                       varStatus="vs">
                                                <tr><!-- + plantBase.city + plantBase.country + plantBase.delivery_address  -->
                                                    <td class='center' style="width: 50px;">${plantBase.id}</td>
                                                    <td class="center">${plantBase.name }</td>
                                                    <td class="center">${plantBase.province}</td>
                                                    <td class="center">${plantBase.delivery_person }</td>
                                                    <td class="center">${plantBase.delivery_phone}</td>
                                                    <td class="center">
                                                        <c:if test="${plantBase.update_time==null}">未修改</c:if>
                                                        <c:if test="${plantBase.update_time!=null}">${plantBase.update_time}</c:if>
                                                    </td>
                                                    <td class="center">
                                                    	<c:if test="${plantBase.status=='00'}">非默认</c:if>
                                                    	<c:if test="${plantBase.status=='01'}">默认</c:if>
                                                    </td>
                                                    <td class="center">
                                                        <c:if test="${QX.edit == 1 }">
                                                            <a class="btn btn-xs btn-success" title="编辑"
                                                               onclick="editPlantBase('${plantBase.id}');">
                                                                <i class="ace-icon fa fa-pencil-square-o bigger-120"
                                                                   title="编辑"></i>
                                                            </a>
                                                        </c:if>
                                                         <c:if test="${QX.del == 1 }">
                                                            <a class="btn btn-mini btn-danger" title="删除"
                                                               onclick="delBase('${plantBase.id}');">
                                                                <i class="ace-icon fa fa-trash-o bigger-120"
                                                                   title="删除"></i>
                                                            </a>
                                                        </c:if>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                        </c:if>
                                        <c:if test="${QX.cha == 0 }">
                                            <tr>
                                                <td colspan="100" class="center">您无权查看</td>
                                            </tr>
                                        </c:if>
                                    </c:when>
                                    <c:otherwise>
                                        <tr class="main_info">
                                            <td colspan="100" class="center">没有相关数据</td>
                                        </tr>
                                    </c:otherwise>
                                </c:choose>
                                </tbody>
                            </table>

                            <div class="page-header position-relative">
                                <table style="width: 100%;">
                                    <tr>
                                        <td style="vertical-align:top;">
                                            <c:if test="${QX.add == 1 }">
                                                <a class="btn btn-mini btn-success" onclick="add();">新增</a>
                                            </c:if>
                                        </td>
                                        <td style="vertical-align: top;">
                                        </td>
                                        <td style="vertical-align: top;">
                                            <div class="pagination"
                                                 style="float: right; padding-top: 0px; margin-top: 0px;">${page.pageStr}</div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../../system/index/foot.jsp" %>
<!-- 删除时确认窗口 -->
<script src="static/ace/js/bootbox.js"></script>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- 日期框 -->
<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
    $(top.hangge());
    $(function () {
        //复选框全选控制
        var active_class = 'active';
        $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function () {
            var th_checked = this.checked;//checkbox inside "TH" table header
            $(this).closest('table').find('tbody > tr').each(function () {
                var row = this;
                if (th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
                else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
            });
        });
    });

    //检索
    function searchs() {
        top.jzts();
        $("#plantbaseForm").submit();
    }

    //新增
    function add() {
    	var baseId=$("#baseId").val();
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "新增发货地址";
        diag.URL = '<%=basePath%>plantbase/goAddD.do?baseId=' + baseId;
        diag.Width = 700;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
        	window.location.href='<%=basePath%>plantbase/goDeliveryList.do?id='+baseId;
        	diag.close();
        };
        diag.show();
    }
    

    // 编辑
    function editPlantBase(id) {
    	var baseId=$("#baseId").val();
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "修改发货地址";
        diag.URL = '<%=basePath%>plantbase/goEditD.do?id='+id+'&baseId='+baseId;
        diag.Width = 700;
        diag.Height = 400;
        diag.CancelEvent = function () { //关闭事件
        	window.location.href='<%=basePath%>plantbase/goDeliveryList.do?id='+baseId;
            diag.close();
        };
        diag.show();
    }
    
    function delBase(id){
    	var baseId=$("#baseId").val();
        bootbox.confirm("确定要删除此地址吗?", function(result) {
            if(result) {
                top.jzts();
                var url = "<%=basePath%>plantbase/deleteD?id="+id;
                $.get(url,function(data){
                    if(data=="success"){
                    }else{
                        alert("删除失败");
                    }
                    window.location.href='<%=basePath%>plantbase/goDeliveryList.do?id='+baseId;
                });
            }
        });
    }


    //批量删除
    function delPlantBases() {
        var str = '';
        for (var i = 0; i < document.getElementsByName('ids').length; i++) {
            if (document.getElementsByName('ids')[i].checked) {
                /* if(document.getElementsByName('ids')[i].id!='00'){
                    alert("");
                    return false;
                } */
                if (str == '') {
                    str += document.getElementsByName('ids')[i].value;
                } else {
                    str += ',' + document.getElementsByName('ids')[i].value;
                }
            }
        }
        if (str == '') {
            alert("请选择选择要删除的种植基地");
            return false;
        } else {
            bootbox.confirm("确定要删除吗?", function (result) {
                if (result) {
                    $.ajax({
                        type: "POST",
                        url: '<%=basePath%>plantbase/deleteP.do?tm=' + new Date().getTime(),
                        data: {ids: str},
                        success: function (data) {
                            if (data == "01") {
                                alert("批量删除成功");
                            }
                            if (data == "00") {
                                alert("批量删除失败");
                            }
                            if (data == "03") {
                                alert("要删除的基地id不能为空");
                            }
                            if (data == "02") {
                                alert("基地下存在区域，不能删除！");
                            }
                            nextPage('${page.currentPage}');
                        }
                    });
                }
            });
        }
    }
</script>
</html>
